package com.example.second.queue;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.second.service.IOrderService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class OrderQueue {

    @Autowired
    IOrderService iOrderService;

    @RabbitListener(queues = "order_queue")
    public void insertQueue(String msg){


        try{
            Map<String,Object>  orderInfo = JSONObject.parseObject(msg, Map.class);
            Map<String,Object>  resultMap = iOrderService.insertOrder(orderInfo);
            if(!(Boolean) resultMap.get("result")){
                System.out.println("order_queue消费消息失败："+orderInfo.get("order_id").toString());
            }
        }catch (Exception e){
            System.out.println("order_queue消费消息失败"+msg);
        }


    }
}
